package com.studentsys.utils;

import javax.servlet.http.Part;
import java.io.File;
import java.io.IOException;
import java.util.UUID;

//文件上传工具类
public class FileUploadUtils {
    public static String uploadPic(Part part) throws IOException {
        //获取上传图片名称
        String pic = part.getSubmittedFileName();
        //处理图片名冲突,在图片名的前面加上一个随机uuid号(16进制数,0-9,a-f)
        pic = UUID.randomUUID()+pic;

        String path="E:\\pic";
        File file = new File(path);
        //判断路径是否存在
        if (file.exists()){
            //创建路径
            file.mkdir();
        }
        //上传"E:\pic"
        part.write(path+"\\"+pic);
        return pic;
    }
}
